package org.brownflat.watergate.domain;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
@Entity
@Table(name="wgate_review_contribution")
public class ReviewContribution extends BaseEntity {

    @ManyToOne
    @JoinColumn(name="contributor")
    private User user;

    @ManyToOne
    @JoinColumn(name="review")
    private Review review;

    @ManyToOne
    @JoinColumn(name="contr_state")
    private ReviewContributionState reviewContributionState;

    @OneToMany
    @JoinTable(
            name = "wgate_review_contr_comment",
            joinColumns = @JoinColumn(name = "contr_id"),
            inverseJoinColumns = @JoinColumn(name = "comment_id")
    )
    private List<Comment> comments = new ArrayList<Comment>();

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Review getReview() {
        return review;
    }

    public void setReview(Review review) {
        this.review = review;
    }

    public ReviewContributionState getReviewContributionState() {
        return reviewContributionState;
    }

    public void setReviewContributionState(ReviewContributionState reviewContributionState) {
        this.reviewContributionState = reviewContributionState;
    }

    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public void addComment(Comment comment) {
        this.comments.add(comment);
    }
}
